u`
Ep.255uC^[tFCXƂ́v

otH[FAWKFp.250 partial01.cs

EMyClassNX̒`AAʃt@Cipartial02.csjƂă\[X悤

쐬Fpartial01.csij

//AWKFp.250 partial01.cs
using System;
partial class MyClass { //MyClassNX̒`@
    public int x;
}
class partial01 { //partial01NX̒`
    public static void Main() {
        MyClass mc = new MyClass();
        mc.x = 10;
        mc.Show();
    }
}

쐬Fpartial02.csij

using System; //쐬
partial class MyClass { //MyClassNX̒`A
    public void Show() {
        Console.WriteLine("x = {0}", x);
    }
}

10 C^[tFCX

p.255 C^[tFCXƂ

EC^[tFCX̌̈Ӗ́uقȂvf֘Atdg݁vuڍʁv
EC#ł́up֌ŴȂNX֘Atdg݁v
EႦ΁AʏɃhSƐ퓬@ьQ[ɂāAhSNXƐ퓬@NXp֌WɂȂ邱Ƃ͍lÂ炢B
@AõNXuśvC^[tFCXĂ()AŝɊ܂܂̂ƂĂ܂Ƃ߂Ĉ
Ê悤ɁANXɊ{NX``ɎŁANXɃC^[tFCXł

p.255 C^[tFCX̐錾

EC^[tFCX͒ۃNXɎ`Œ`ANXOIɒۉ̂ɂȂ
E̓Iɂ́Aۃ\bhAۃvpeBAۃCfNT݂̂Ƃł̂C^[tFCX
EۃNXƂ͈قȂAP̃NXŕ̃C^[tFCXłiNX̌p͂P̂݁j
E͗Ⴆ΁uŝłAŝł}Vv̏ꍇ
EC^[tFCX̒`F interface C^[tFCX {c}
Eۃ\bh̒`F ߂l^ \bh(Xg);
EۃvpeB̒`F ߂l^ vpeB { get; set; } getset̂ǂ炩͏ȗ
EۃCfNT̒`F ߂l^ this(CfbNX^ CfbNX);
EC^[tFCX̒`F interface Flyable { string HowToFly(); } //ŝC^[tFCX

p.256 C^[tFCX̎

ENX̌pƓŁAC^[tFCX̎\
EF class Dragon : Flyable {c}
ENX̌pƂ͈قȂÃC^[tFCX̎\
EF class Dragon : Flyable, Swimable {c}
EۃNX̌pƓlɁAC^[tFCXNXł͒ۃõI[oChɂ(̉)߂
E̎AoverrideL[[h͕svApublic\bhɂ邱
EF class Dragon : Flyable { public string HowToFly() { return "Ŕ"; } }
ENX𗘗p鑤猩ƁAC^[tFCXĂNXł̓C^[tFCX̃NX̐\ƂɂȂAbg傫

p.257 interface01.cs

//p.257 interface01.cs
using System;
interface IMyInterface { //C^[tFCX̒`
    void show(string str); //ۃ\bh
    int xprop { get; set; } //ۃvpeB
    int this[int i] { get; set; } //ۃCfNT
}
class MyClass : IMyInterface { //C^[tFCXNX
    int i; //J̃f[^o uprotectedv͕sv
    int[] arr = new int[10]; //J̔z
    public void show(string str) { //ۃ\bh̃I[oCh(ۉ)
        Console.WriteLine(str);
    }
    public int xprop { //ۃvpeB̃I[oCh(ۉ)
        get { return i; } set { i = value; }
    }
    public int this[int index] { //ۃCfNT̃I[oCh(ۉ)
        get { return arr[index]; } set { arr[index] = value; }
    }       
}
class interface01 {
    public static void Main() {
        MyClass mc = new MyClass(); //C^[tFCXNX
        mc.show("Test Interface"); //ۃ\bh̃I[oCh(set)Ă
        mc.xprop = 100; //ۃvpeB̃I[oCh(set)Ă
        Console.WriteLine("mc.xprop = {0}", mc.xprop); //ۃ\bh̃I[oCh(get)Ă
        for (int i = 0; i < 10; i++) {
            mc[i] = i * 2; //ۃCfNT̃I[oCh(set)Ă
        }
        for (int i = 0; i < 10; i++) {
            Console.WriteLine("mc[{0}] = {1}", i, mc[i]); //ۃCfNT̃I[oCh(get)Ă
        }        
    }
}

p.259 1̃C^[tFCX𕡐̃NXŎ

Ep֌ŴȂ̃NXAC^[tFCXNXƂāA֘At邱Ƃł
EC^[tFCXĂNXł΁AۃõI[oCh邱Ƃۏ؂邱Ƃ|Cg

p.259 interface02.cs

//p.259 interface02.cs
using System;
interface IMyInterface { //C^[tFCX̒`
    void show(string str); //ۃ\bh
}
class MyClass : IMyInterface { //C^[tFCXNX@
    public void show(string s) { //ۃ\bh̃I[oCh@
        Console.WriteLine(s);
    }
}
class YourClass : IMyInterface { //C^[tFCXNXA
    public void show(string x) { //ۃ\bh̃I[oChA
        Console.WriteLine("{0}͂܂", x);
    }
}
class interface02 {
    public static void Main() {
        MyClass mc = new MyClass();
        YourClass yc = new YourClass();
        mc.show("abc"); //ۃ\bh̃I[oCh@Ă
        yc.show("abc"); //ۃ\bh̃I[oChAĂ
    }
}

p.260iC^[tFCX^ƂQƕϐj

EۃNX̃CX^X͐łȂ̂ƓlɁAC^[tFCX̃CX^X͐łȂ
EۃNX^ƂQƕϐ`ł̂ƂƓlɁAC^[tFCX^ƂQƕϐ`ł
EۃNXAphNXB̃CX^X́AA^ƂĈƂł
ElɁAC^[tFCXCNXD̃CX^X́AC^ƂĈƂł
EF ׂ̂łhŚuFhv́ẤׂuFhvł
@inteface Flyable {}
@class Dragon : Flyable {}
@class Test { void Play() { Dragon Veldra = new Dragon(); Flyable flyone = Veldra; }
EȂAC^[tFCX^Ƃz`łAvfƂāAC^[tFCXNX̃CX^Xi[ł
EF ׂ̂łhŚuFhv́Aׂ̔z[0]ł

p.261 interface03.cs

//p.261 interface03.cs
using System;
interface IMyInterface { //C^[tFCX̒`
    int calc(int x, int y); //ۃ\bh
}
class Plus : IMyInterface { //C^[tFCXNX@
    public int calc(int a, int b) { //ۃ\bh̃I[oCh@uvZv͉ZƂ
        return a + b;
    }
}
class Minus : IMyInterface { //C^[tFCXNXA
    public int calc(int a, int b) { //ۃ\bh̃I[oChAuvZv͌ZƂ
        return a - b;
    }
}
class interface03 {
    public static void Main() {
        IMyInterface im; //C^[tFCX^ƂQƕϐ
        Plus p = new Plus();
        Minus m = new Minus();
        im = p; //PlusNX̓C^[tFCXĂ̂ŃC^[tFCX^ƂQƕϐɑ
        Console.WriteLine("im.calc = {0}", im.calc(3, 5)); //ۃ\bh̃I[oChƕۏ؂
        im = m; //MinusNX̓C^[tFCXĂ̂ŃC^[tFCX^ƂQƕϐɑ
        Console.WriteLine("im.calc = {0}", im.calc(3, 5)); //ۃ\bh̃I[oChƕۏ؂
    }
}

AWKFp.261 interface03.cs

EC^[tFCX̒`LɕύX
  interface Flyable { string HowToFly(); } //ŝC^[tFCX
ENXLɕύX
  class Dragon : Flyable { public string HowToFly() { return "r͂Ŕ"; } }
  class F16 : Flyable { public string HowToFly() { return "WFbgŔ"; } }
EԐ邱ƂmF悤

쐬

//AWKFp.261 interface03.cs
using System;
interface Flyable { string HowToFly(); } //ŝC^[tFCX
class Dragon : Flyable { //C^[tFCXNX@
    public string HowToFly() { return "r͂Ŕ"; } //ۃ\bh̃I[oCh@
}
class F16 : Flyable { //C^[tFCXNXA
    public string HowToFly() { return "WFbgŔ"; } //ۃ\bh̃I[oChA
}
class interface03 {
    public static void Main() {
        Flyable flyer; //C^[tFCX^ƂQƕϐ
        Dragon Veldra = new Dragon();
        F16 Blue = new F16();
        flyer = Veldra; //DragonNX̓C^[tFCXĂ̂ŃC^[tFCX^ƂQƕϐɑ
        Console.WriteLine("flyer.HowToFly = {0}", flyer.HowToFly()); //ۃ\bh̃I[oChƕۏ؂
        flyer = Blue; //F16NX̓C^[tFCXĂ̂ŃC^[tFCX^ƂQƕϐɑ
        Console.WriteLine("flyer.HowToFly = {0}", flyer.HowToFly()); //ۃ\bh̃I[oChƕۏ؂
    }
}

AWKFp.261 interface03.cs Â

EFlyableC^[tFCX^̔zɊi[悤ɂ悤

쐬

//AWKFp.261 interface03.cs
using System;
interface Flyable { string HowToFly(); } //ŝC^[tFCX
class Dragon : Flyable { //C^[tFCXNX@
    public string HowToFly() { return "r͂Ŕ"; } //ۃ\bh̃I[oCh@
}
class F16 : Flyable { //C^[tFCXNXA
    public string HowToFly() { return "WFbgŔ"; } //ۃ\bh̃I[oChA
}
class interface03 {
    public static void Main() {
        Dragon Veldra = new Dragon();
        F16 Blue = new F16();
        Flyable[] flyers = { Veldra, Blue }; //LC^[tFCX^ƂzɊi[
        foreach (var w in flyers) { //z̑SvfɂČJԂ
            Console.WriteLine(w.HowToFly()); //ۃ\bh̃I[oChƕۏ؂
        }
    }
}

p.263 ̃C^[tFCX

EPNXŕ̃NXp邱Ƃ͂łȂ
EPNXŕ̃C^[tFCX邱Ƃ͉\
EF class NX : C^[tFCX@, C^[tFCXA, c {c}
ESẴC^[tFCX̒ۃõI[oCh߂
EF
interface Flyable { string HowToFly(); } //ŝC^[tFCX
interface Runable { string HowToRun(); } //ŝC^[tFCX
class Dragon : Flyable, Runable {
  public string HowToFly() { return "r͂Ŕ"; }
  public string HowToRun() { return "r͂ő"; }
}

p.263 interface04.cs 

E010sځuinterface ISecond : IFirstvuinterface ISecondv

p.263 interface04.cs

//p.263 interface04.cs
using System;
interface IFirst { //C^[tFCX@̒`
    void show(int x); //ۃ\bh@
}
interface ISecond { //C^[tFCXA̒`
    void show(int x, int y); //ۃ\bhA
}
class MyClass : IFirst, ISecond { //C^[tFCX@ƇANX
    public void show(int x) { //ۃ\bh@̃I[oCh
        Console.WriteLine("x = {0}", x);
    }
    public void show(int x, int y) { //ۃ\bhÃI[oChŃI[o[[hɂȂ
        Console.WriteLine("x = {0}, y = {1}", x, y);
    }
}
class interface04 {
    public static void Main() {
        MyClass mc = new MyClass();
        mc.show(2); //ۃ\bh@̃I[oChĂ
        mc.show(1, 3); //ۃ\bhÃI[oChĂ
    }
}

p.263 (̓VOj`̃\bhC^[tFCX)

EPNXŕ̃C^[tFCX鎞AɓVOj`̃\bhƂP̃I[oChŗɓĂ͂܂AG[ɂ͂ȂȂ
@eLXgł́uĎKvvƂȂĂ邪G[ɂȂ킯ł͂Ȃ

AWKFp.263 interface04.cs

Euvoid show(int x, int y); //ۃ\bhAvuvoid show(int y); //ۃ\bhAvƂĂA邱ƂmF

쐬

//AWKFp.263 interface04.cs
using System;
interface IFirst { //C^[tFCX@̒`
    void show(int x); //ۃ\bh@
}
interface ISecond { //C^[tFCXA̒`
    void show(int y); //ۃ\bhA @ƓVOj`
}
class MyClass : IFirst, ISecond { //C^[tFCX@ƇANX
    public void show(int x) { //ۃ\bh@̃I[oChÃI[oCh
        Console.WriteLine("x = {0}", x);
    }
    public void show(int x, int y) { //I[oChł͂ȂÕ\bhŃI[o[[hɂȂ
        Console.WriteLine("x = {0}, y = {1}", x, y);
    }
}
class interface04 {
    public static void Main() {
        MyClass mc = new MyClass();
        mc.show(2); //ۃ\bh@ÃI[oChĂ
        mc.show(1, 3); //I[o[[hĂ
    }
}

p.263 (̓VOj`̃\bhC^[tFCX)F

EPNXŕ̃C^[tFCX鎞AɓVOj`̃\bhƂP̃I[oChŗɓĂ͂܂Aǂ̃C^[tFCX^ƂϐoRĂs


AWKFp.263 interface04.cs 

EMyClass̕ϐC^[tFCX@^ɑĒۃ\bh@̃I[oChĂ
EMyClass̕ϐC^[tFCXA^ɑĒۃ\bhÃI[oChĂ
Eǂ邱ƂmF

쐬

//AWKFp.263 interface04.cs
using System;
interface IFirst { //C^[tFCX@̒`
    void show(int x); //ۃ\bh@
}
interface ISecond { //C^[tFCXA̒`
    void show(int y); //ۃ\bhA @ƓVOj`
}
class MyClass : IFirst, ISecond { //C^[tFCX@ƇANX
    public void show(int x) { //ۃ\bh@̃I[oChÃI[oCh
        Console.WriteLine("x = {0}", x);
    }
    public void show(int x, int y) { //I[oChł͂ȂÕ\bhŃI[o[[hɂȂ
        Console.WriteLine("x = {0}, y = {1}", x, y);
    }
}
class interface04 {
    public static void Main() {
        MyClass mc = new MyClass();
        IFirst ifi = mc; //C^[tFCX@^ɑ
        ifi.show(2); //ۃ\bh@̃I[oChĂ
        ISecond ise = mc; //C^[tFCXA^ɑ
        ise.show(1); //ۃ\bhÃI[oChĂ
    }
}

p.263 (̓VOj`̃\bhC^[tFCX)FeLXgp.264

EPNXŕ̃C^[tFCX鎞AɓVOj`̃\bhƂɁAʂăI[oChꍇ́uC^[tFCX.vOuƗǂ
Es\bh͎IpublicɂȂApublicw肷ƃG[ɂȂ̂Œ

AWKFp.263 interface04.cs 

Eۃ\bh@̃I[oChÃI[oChłupublic void show(int x)vʂăI[oChēmF悤
Eupublic void show(int x, int y)v͍폜ėǂ

쐬

//AWKFp.263 interface04.cs
using System;
interface IFirst { //C^[tFCX@̒`
    void show(int x); //ۃ\bh@
}
interface ISecond { //C^[tFCXA̒`
    void show(int y); //ۃ\bhA @ƓVOj`
}
class MyClass : IFirst, ISecond { //C^[tFCX@ƇANX
    void IFirst.show(int x) { //ۃ\bh@̃I[oCh
        Console.WriteLine("IFirst = {0}", x);
    }
    void ISecond.show(int x) { //ۃ\bhÃI[oCh
        Console.WriteLine("ISecond = {0}", x);
    }
}
class interface04 {
    public static void Main() {
        MyClass mc = new MyClass();
        IFirst ifi = mc; //C^[tFCX@^ɑ
        ifi.show(1); //ۃ\bh@̃I[oChĂ
        ISecond ise = mc; //C^[tFCXA^ɑ
        ise.show(2); //ۃ\bhÃI[oChĂ
    }
}

yQlz̓IȎ

using System;
interface ׂ { string ѕ(); }
interface Fׂ { string ѕ(); }
class Mh : ׂ, Fׂ { //2C^[tFCXNX
    string ׂ.ѕ() { return "C𗘗p"; } //@.\bh̃I[o[Ch
    string Fׂ.ѕ() { return "C𗘗pȂ"; } //A.\bh̃I[o[Ch
}
class  {
    public static void Main() {
        Mh king = new Mh();
        ׂ b = king; //C^[tFCX^Ƃϐ@
        Console.WriteLine(b.ѕ()); //C𗘗p
        Fׂ b = king; //C^[tFCX^ƂϐA
        Console.WriteLine(b.ѕ()); //C𗘗pȂ
    }
}

p.264 interface05.csɂ

E005sڂ́upublicv͕sv
E010sڂ́upublicv͕sv

p.265 interface05.cs

//p.265 interface05.cs
using System;
interface IMas { //ułE܂vC^[tFCX@
    void show(int i); //ۃ\bh@
}
interface IDa { //uEłvC^[tFCXA
    void show(int i); //ۃ\bhA @ƓVOj`
}
class MyClass : IMas, IDa { //LQC^[tFCXNX
    void IMas.show(int i) { //ۃ\bh@̃I[oChȂ̂ŁułE܂v
        Console.WriteLine("i{0}ł", i);
    }
    void IDa.show(int i) { //ۃ\bhÃI[oChȂ̂ŁuEłv
        Console.WriteLine("i{0}", i);
    }
}
class interface05 {
    public static void Main() {
        IMas im; //C^[tFCX@^̕ϐ
        IDa id; //C^[tFCXA^̕ϐ
        MyClass mc = new MyClass(); //C^[tFCX@ANX̃IuWFNg
        im = mc; //C^[tFCX@^̕ϐɑ
        im.show(5); //ۃ\bh@̃I[oChs
        id = mc; //C^[tFCXA^̕ϐɑ
        id.show(5); //ۃ\bhÃI[oChs
    }
}

y⑫zNX̌pƃC^[tFCX̎

ENX̌pƃC^[tFCX͓̎ɍsƂł
EA{NXC^[tFCXOɋLq邱
EF class hNX : {NX, C^[tFCX@, C^[tFCXA {c}
EȂAۃNX̌pƃC^[tFCX̎𓯎ɍsƂł
E̎AVOj`̒ۃ\bhC^[tFCX邱Ƃ\

AWKFp.265 interface05.cs

EۃNX̌pƃC^[tFCX̎𓯎ɍsƂł邱ƂmF悤

쐬

//AWKFp.265 interface05.cs
using System;
interface IMas { //ułE܂vC^[tFCX@
    void show(int i); //ۃ\bh@
}
interface IDa { //uEłvC^[tFCXA
    void show(int i); //ۃ\bhA @ƓVOj`
}
abstract class Base { //yǉzۃNX
    public abstract void show(int i); //ۃ\bhB
}
class MyClass : Base, IMas, IDa { //yύXzۃNXpQC^[tFCXNX
    void IMas.show(int i) { //ۃ\bh@̃I[oChȂ̂ŁułE܂v
        Console.WriteLine("i{0}ł", i);
    }
    void IDa.show(int i) { //ۃ\bhÃI[oChȂ̂ŁuEłv
        Console.WriteLine("i{0}", i);
    }
    public override void show(int i) { //yǉzۃ\bhB̃I[oCh
        Console.WriteLine("i{0}", i);
    }
}
class interface05 {
    public static void Main() {
        IMas im; //C^[tFCX@^̕ϐ
        IDa id; //C^[tFCXA^̕ϐ
        MyClass mc = new MyClass(); //C^[tFCX@ANX̃IuWFNg
        im = mc; //C^[tFCX@^̕ϐɑ
        im.show(5); //ۃ\bh@̃I[oChs
        id = mc; //C^[tFCXA^̕ϐɑ
        id.show(5); //ۃ\bhÃI[oChs
        mc.show(5); //yǉzC^[tFCX^̕ϐoRȂƒۃ\bhB̃I[oChs
    }
}

oF~jK mini266.cs

EuAWKFp.265 interface05.csvIDaC^[tFCXOāAmF悤

(bR[XŏI)\Fp.266uC^[tFCX̌pvi 9̗͂Ks܂j

